package com.reborn.mall.api.service.impl;

import com.reborn.mall.api.common.util.AliyunOSSUtil;
import com.reborn.mall.api.common.util.BeanUtil;
import com.reborn.mall.api.model.dto.HomeAdvertiseDTO;
import com.reborn.mall.api.model.entity.HomeAdvertise;
import com.reborn.mall.api.service.HomeAdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * TODO: Here is description
 *
 * @author Reborn
 * @since 2020/4/30
 */
@Service
public class HomeAdvertiseServiceImpl extends BaseServiceImpl<HomeAdvertise> implements HomeAdvertiseService {

    @Autowired
    private AliyunOSSUtil aliyunOSSUtil;

    @Override
    public HomeAdvertise create(HomeAdvertiseDTO homeAdvertiseDTO) {
        HomeAdvertise homeAdvertise = BeanUtil.copyProperties(homeAdvertiseDTO, HomeAdvertise.class);
        MultipartFile picFile = homeAdvertiseDTO.getPicFile();
        if (picFile != null) {
            String filePath = aliyunOSSUtil.uploadFile(picFile);
            homeAdvertise.setPic(filePath);
        }
        return insertSelective(homeAdvertise);
    }
}
